# -*- coding: utf-8 -*-
"""
Created on Tue Apr 12 13:13:04 2022

@author: mizhi
"""

import pandas as pd
import sys
import os
import joblib
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.feature_selection import VarianceThreshold
from sklearn.tree import DecisionTreeClassifier, export_graphviz,DecisionTreeRegressor
from sklearn.linear_model import LinearRegression, SGDRegressor, Ridge
from sklearn.metrics import mean_squared_error
def liner():
    path = "PressureData.csv"
    data = pd.read_csv(path)
    data.dropna(inplace=True)
    transfer = VarianceThreshold(threshold=10)
    data_new = transfer.fit_transform(data)
    x = data.iloc[:,0:3]
    #print(x)
    y = data.iloc[:,3:]
    #print(y)
    
    x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=22)
    transfer = StandardScaler()
    x_train = transfer.fit_transform(x_train)
    x_test = transfer.transform(x_test)

    # 4）预估器
    estimator = Ridge(alpha=0.5, max_iter=10000)
    estimator.fit(x_train, y_train)
    y_predict = estimator.predict(x_test)
    error = mean_squared_error(y_test, y_predict)
    y_predict = estimator.predict(x_test)
    error = mean_squared_error(y_test, y_predict)
    return estimator,error
if __name__ == "__main__":
    a = []
    for i in range(1, len(sys.argv)):
        a.append(sys.argv[i])
    #print(a)
    data = pd.DataFrame([{"Hour":float(a[0]),"Minute":float(a[1]),"Temperature":float(a[2])}])
    estimator,error = liner()
    predict = estimator.predict(data)
    print(predict[0][0])
    print(error)
    #tree()